package e.odbo.data.model.smaple;

import e.odbo.data.model.Column;
import e.odbo.data.model.ColumnType;
import e.odbo.data.model.ForeignKeyFlag;
import e.odbo.data.model.I_ColumnGather;

public abstract class UserLogAble<T> implements I_ColumnGather {
    public final static int TABLE_FLAG_USERLOG=PK.TABLE_FLAG_PK<<3;

    public final static String CREATE_USER_SYS="CREATE_USER_SYS";

    public final static String MODIFIED_USER_SYS="MODIFIED_USER_SYS";


    public static UserLogAble Instance_INT(final String refTable, final String refPK){
        return new UserLogAble<Integer>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.INT;
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK);
            }
        };
    }

    public static UserLogAble Instance_INT(final String refTable, final String refPK, final ForeignKeyFlag refCascade_del, final ForeignKeyFlag refCascade_update){
        return new UserLogAble<Integer>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.INT;
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK,refCascade_del,refCascade_update);
            }
        };
    }

    public static UserLogAble Instance_STRING(final String refTable, final String refPK){
        return new UserLogAble<String>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.VARCHAR(255);
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK);
            }
        };
    }

    public static UserLogAble Instance_STRING(final String refTable, final String refPK, final ForeignKeyFlag refCascade_del, final ForeignKeyFlag refCascade_update){
        return new UserLogAble<String>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.VARCHAR(255);
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK,refCascade_del,refCascade_update);
            }
        };
    }

    public static UserLogAble Instance_LONG(final String refTable, final String refPK){
        return new UserLogAble<Long>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.LONG;
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK);
            }
        };
    }

    public static UserLogAble Instance_LONG(final String refTable, final String refPK, final ForeignKeyFlag refCascade_del, final ForeignKeyFlag refCascade_update){
        return new UserLogAble<Long>() {
            @Override
            public ColumnType getColumnType() {
                return ColumnType.LONG;
            }

            @Override
            public Column addRef(Column column) {
                return column.ref(refTable,refPK,refCascade_del,refCascade_update);
            }
        };
    }

    @Override
    public Column[] getColumns() {
        return new Column[]{
                addRef(Column.c(CREATE_USER_SYS,getColumnType(),"create user").NotNull()),
                Column.c(MODIFIED_USER_SYS,getColumnType(),"modified user").NotNull()
        };
    }

    public abstract ColumnType<T> getColumnType();

    public abstract Column addRef(Column column);

    @Override
    public int addTableFlags() {
        return TABLE_FLAG_USERLOG;
    }
}
